package com.learn.dead_letter;

import com.learn.utils.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/08/23
 * @description ch06 死信
 */
public class Producer {
    public static final String NORMAL_EXCHANGE = "normal_exchange";
    public static final String NORMAL_ROUTING_KEY = "normal";
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();

        for (int i = 0; i < 10; i++) {
            String msg = "msg0" + i;
            // 在这里也可以设置ttl, 建造者模式
            AMQP.BasicProperties properties = new AMQP.BasicProperties().builder()
                            .expiration("5000")
                                    .build();
            channel.basicPublish(NORMAL_EXCHANGE, NORMAL_ROUTING_KEY,
                    null,
                    msg.getBytes(StandardCharsets.UTF_8));
        }
    }
}
